import 'package:flutter/material.dart';

class EMPColor {
  static var text_disabled = Color.fromARGB(60, 255, 0, 0);
  static var dark_text_disabled = Color.fromARGB(166, 255, 0, 0);

  static var dark_button_text = Color.fromARGB(99, 200, 255, 90);

  static var button_disabled = Color.fromARGB(175, 200, 200, 54);
  static var dark_button_disabled = Color.fromARGB(218, 200, 200, 54);

  static var app_main = Colors.blue.shade300;

  static var dark_app_main = Color.fromARGB(255, 154, 161, 170);
}

class EMPButton extends StatelessWidget {
  final String text;
  final double fontSize;
  final Color? textColor;
  final Color? disabledTextColor;
  final Color? backgroundColor;
  final Color? disabledBackgroundColor;
  final double? minHeight;
  final double? minWidth;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry padding;
  final double radius;
  final BorderSide side;
  final bool isDark;

  const EMPButton(
      {super.key,
      required this.text,
      this.fontSize = 14.0,
      this.padding = const EdgeInsets.all(8.0),
      this.radius = 0,
      this.side = const BorderSide(),
      this.isDark = true,
      this.textColor,
      this.disabledTextColor,
      this.backgroundColor,
      this.disabledBackgroundColor,
      this.minHeight,
      this.minWidth,
      this.onPressed});

  @override
  Widget build(BuildContext context) {
    return TextButton(
        onPressed: onPressed,
        style: ButtonStyle(
          // 文字颜色
          foregroundColor: MaterialStateProperty.resolveWith(
            (states) {
              if (states.contains(MaterialState.disabled)) {
                return disabledTextColor ??
                    (isDark
                        ? EMPColor.dark_text_disabled
                        : EMPColor.text_disabled);
              }
              return textColor ??
                  (isDark ? EMPColor.dark_button_text : Colors.white);
            },
          ),
          // 背景颜色
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.disabled)) {
              return disabledBackgroundColor ??
                  (isDark
                      ? EMPColor.dark_button_disabled
                      : EMPColor.button_disabled);
            }
            return backgroundColor ??
                (isDark ? EMPColor.dark_app_main : EMPColor.app_main);
          }),
          // 水波纹
          overlayColor: MaterialStateProperty.resolveWith((states) {
            return (textColor ??
                    (isDark ? EMPColor.dark_button_text : Colors.white))
                .withOpacity(0.12);
          }),
          // 按钮最小大小
          minimumSize: (minWidth == null || minHeight == null)
              ? null
              : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
          padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
          shape: MaterialStateProperty.all<OutlinedBorder>(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(radius),
            ),
          ),
          side: MaterialStateProperty.all<BorderSide>(side),
        ),
        child: Text(
          text,
          style: TextStyle(fontSize: fontSize),
        ));
  }
}
